package mainPackage;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class ResolutionInfo extends JFrame {

	private int width;
	private int height;
	
	public ResolutionInfo(boolean fullscreen) {
		
		int windowHeight = 0;
		int options = 0;
		
		if (fullscreen == false) {
			windowHeight = 150;
			options = 2;
		}
		if (fullscreen == true) {
			windowHeight = 300;
			options = 6;
		}
		
		this.setBounds(0, 0, 325, windowHeight);
		
		Toolkit tools = Toolkit.getDefaultToolkit();
		Dimension screen = tools.getScreenSize();
		int screenX = (int) screen.getWidth();
		int screenY = (int) screen.getHeight();
		int windowX = this.getWidth();
		int windowY = this.getHeight();
		int xPosition = (screenX - windowX) / 2;
		int yPosition = (screenY - windowY) / 2;
		this.setLocation(xPosition, yPosition);
		
		JPanel panel = new JPanel();
				
		JLabel label = new JLabel ("At which resolution would you like to run the game?", JLabel.CENTER);
		JButton SVGA = new JButton("800 x 600");
		JButton XGA = new JButton("1024 x 768");
		JButton HD720 = new JButton("1280 x 720");
		JButton WXGA = new JButton("1280 x 768");
		JButton WXGA2 = new JButton("1280 x 800");
		JButton SXGA = new JButton("1280 x 1024");
		JButton WSXGA = new JButton("1440 x 900");
		JButton WWSXGA = new JButton("1600 x 900");
		
		MyActionListener Lsvga = new MyActionListener(this, 800, 600);
		MyActionListener Lxga = new MyActionListener(this, 1024, 768);
		MyActionListener Lhd720 = new MyActionListener(this, 1280, 720);
		MyActionListener Lwxga = new MyActionListener(this, 1280, 768);
		MyActionListener Lwxga2 = new MyActionListener(this, 1280, 800);
		MyActionListener Lsxga = new MyActionListener(this, 1280, 1024);
		MyActionListener Lwsxga = new MyActionListener(this, 1440, 900);
		MyActionListener Lwwsxga = new MyActionListener(this, 1600, 900);
		
		SVGA.addActionListener(Lsvga);
		XGA.addActionListener(Lxga);
		HD720.addActionListener(Lhd720);
		WXGA.addActionListener(Lwxga);
		WXGA2.addActionListener(Lwxga2);
		SXGA.addActionListener(Lsxga);
		WSXGA.addActionListener(Lwsxga);
		WWSXGA.addActionListener(Lwwsxga);
		
		panel.setLayout(new GridBagLayout());
		
		GridBagConstraints Clab = new GridBagConstraints();
		Clab.weightx = 100;
		Clab.weighty = 100;
		Clab.gridx = 0;
		Clab.gridy = 0;
		Clab.gridwidth = 1;
		Clab.gridheight = 1;
		
		GridBagConstraints Csvga = new GridBagConstraints();
		Csvga.weightx = 100;
		Csvga.weighty = 100;
		Csvga.gridx = 0;
		Csvga.gridy = 1;
		Csvga.gridwidth = 1;
		Csvga.gridheight = 1;
		
		GridBagConstraints Cxga = new GridBagConstraints();
		Cxga.weightx = 100;
		Cxga.weighty = 100;
		Cxga.gridx = 0;
		Cxga.gridy = 2;
		Cxga.gridwidth = 1;
		Cxga.gridheight = 1;
		
		GridBagConstraints Chd720 = new GridBagConstraints();
		Chd720.weightx = 100;
		Chd720.weighty = 100;
		Chd720.gridx = 0;
		Chd720.gridy = 3;
		Chd720.gridwidth = 1;
		Chd720.gridheight = 1;
		
		GridBagConstraints Cwxga = new GridBagConstraints();
		Cwxga.weightx = 100;
		Cwxga.weighty = 100;
		Cwxga.gridx = 0;
		Cwxga.gridy = 4;
		Cwxga.gridwidth = 1;
		Cwxga.gridheight = 1;
		
		GridBagConstraints Cwxga2 = new GridBagConstraints();
		Cwxga2.weightx = 100;
		Cwxga2.weighty = 100;
		Cwxga2.gridx = 0;
		Cwxga2.gridy = 5;
		Cwxga2.gridwidth = 1;
		Cwxga2.gridheight = 1;
		
		GridBagConstraints Csxga = new GridBagConstraints();
		Csxga.weightx = 100;
		Csxga.weighty = 100;
		Csxga.gridx = 0;
		Csxga.gridy = 6;
		Csxga.gridwidth = 1;
		Csxga.gridheight = 1;
		
		GridBagConstraints Cwsxga = new GridBagConstraints();
		Cwsxga.weightx = 100;
		Cwsxga.weighty = 100;
		Cwsxga.gridx = 0;
		Cwsxga.gridy = 7;
		Cwsxga.gridwidth = 1;
		Cwsxga.gridheight = 1;
		
		GridBagConstraints Cwwsxga = new GridBagConstraints();
		Cwwsxga.weightx = 100;
		Cwwsxga.weighty = 100;
		Cwwsxga.gridx = 0;
		Cwwsxga.gridy = 8;
		Cwwsxga.gridwidth = 1;
		Cwwsxga.gridheight = 1;		
		
		panel.add(label, Clab);
		panel.add(SVGA, Csvga);
		panel.add(XGA, Cxga);
		if (fullscreen == true) {
			panel.add(HD720, Chd720);
			panel.add(WXGA, Cwxga);
			panel.add(WXGA2, Cwxga2);
			panel.add(SXGA, Csxga);
			panel.add(WSXGA, Cwsxga);
			panel.add(WWSXGA, Cwwsxga);
		}
		
		GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
		GraphicsDevice device = ge.getDefaultScreenDevice();
		DisplayMode[] modes = device.getDisplayModes();
		
		boolean Bsvga = false;
		boolean Bxga = false;
		boolean Bhd720 = false;
		boolean Bwxga = false;
		boolean Bwxga2 = false;
		boolean Bsxga = false;
		boolean Bwsxga = false;
		boolean Bwwsxga = false;
		
		if (modes.length != 0) {
			for (int i = 0; i < modes.length; i++) {
				if (modes[i].getWidth() == 800 && modes[i].getHeight() == 600 && modes[i].getBitDepth() == 32) {
					Bsvga = true;
				}
				if (modes[i].getWidth() == 1024 && modes[i].getHeight() == 768 && modes[i].getBitDepth() == 32) {
					Bxga = true;
				}
				if (modes[i].getWidth() == 1280 && modes[i].getHeight() == 720 && modes[i].getBitDepth() == 32) {
					Bhd720 = true;
				}
				if (modes[i].getWidth() == 1280 && modes[i].getHeight() == 768 && modes[i].getBitDepth() == 32) {
					Bwxga = true;
				}
				if (modes[i].getWidth() == 1280 && modes[i].getHeight() == 800 && modes[i].getBitDepth() == 32) {
					Bwxga2 = true;
				}
				if (modes[i].getWidth() == 1280 && modes[i].getHeight() == 1024 && modes[i].getBitDepth() == 32) {
					Bsxga = true;
				}
				if (modes[i].getWidth() == 1440 && modes[i].getHeight() == 900 && modes[i].getBitDepth() == 32) {
					Bwsxga = true;
				}
				if (modes[i].getWidth() == 1600 && modes[i].getHeight() == 900 && modes[i].getBitDepth() == 32) {
					Bwwsxga = true;
				}
			}
		}
		
		if (Bsvga == false) {
			SVGA.setEnabled(false);
		}
		if (Bxga == false) {
			XGA.setEnabled(false);
		}
		if (Bhd720 == false) {
			HD720.setEnabled(false);
		}
		if (Bwxga == false) {
			WXGA.setEnabled(false);
		}
		if (Bwxga2 == false) {
			WXGA2.setEnabled(false);
		}
		if (Bsxga == false) {
			SXGA.setEnabled(false);
		}
		if (Bwsxga == false) {
			WSXGA.setEnabled(false);
		}
		if (Bwwsxga == false) {
			WWSXGA.setEnabled(false);
		}
		
		
				
		this.add(panel);
		
	}
	
	public void setResWidth(int w) {
		width = w;
	}
	public void setResHeight(int h) {
		height = h;
	}
	
	public int getResWidth() {
		return width;
	}
	public int getResHeight() {
		return height;
	}
	
	
	private class MyActionListener implements ActionListener {
		private ResolutionInfo RI;
		private int w;
		private int h;
		public MyActionListener(ResolutionInfo ResInfo, int width, int height) {
			RI = ResInfo;
			w = width;
			h = height;
		}
		public void actionPerformed(ActionEvent e) {
			RI.setResWidth(w);
			RI.setResHeight(h);
			RI.setVisible(false);
		}
	}
}




